package com.briup.mt.service.impl;

import com.briup.mt.bean.BaseConfig;
import com.briup.mt.bean.BaseConfigExample;
import com.briup.mt.bean.BaseFile;
import com.briup.mt.bean.BaseFileExample;
import com.briup.mt.dao.BaseFileMapper;
import com.briup.mt.service.IBaseFileService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 姜鑫
 * @version 1.0
 * @date 2020/12/16 11:10
 */
@Service
public class BaseFileServiceImpl implements IBaseFileService {
    @Resource
    private BaseFileMapper baseFileMapper;

    @Override
    public List<BaseFile> query(String fileName) {
        BaseFileExample example = new BaseFileExample();
        if ((!StringUtils.isEmpty(fileName))){
            example.createCriteria().andFileNameLike("%" + fileName + "%");
        }
        return baseFileMapper.selectByExample(example);
    }

    @Override
    public void saveOrUpdate(BaseFile baseFile) {
        if (baseFile.getId() == null) {
            baseFileMapper.insert(baseFile);
        } else {
            baseFileMapper.updateByPrimaryKey(baseFile);
        }
    }

    @Override
    public void deleteById(String id) {

        baseFileMapper.deleteByPrimaryKey(id);
    }
}